package thread;

//测试线程优先级
public class TestPriority implements Runnable{

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + "priority:" + Thread.currentThread().getPriority());

    }

    public static void main(String[] args) {
        //主线程默认优先级
        System.out.println(Thread.currentThread().getName() + "priority:" + Thread.currentThread().getPriority());


        TestPriority testPriority = new TestPriority();
        Thread t1 = new Thread(testPriority);
        Thread t2 = new Thread(testPriority);
        Thread t3 = new Thread(testPriority);
        Thread t4 = new Thread(testPriority);
        Thread t5 = new Thread(testPriority);

        //先设置优先级再启动
        t1.start();

        t2.setPriority(1);
        t2.start();

        t3.setPriority(4);
        t3.start();

        t4.setPriority(10);
        t4.start();

//        t5.setPriority(-1);
//        t5.start();
    }
}
